package com.brucekong.slm.controller.message;

import com.brucekong.slm.common.PageResult;
import com.brucekong.slm.common.Result;
import com.brucekong.slm.model.forum.ForumDomain;
import com.brucekong.slm.model.forum.ReplyDomain;
import com.brucekong.slm.model.message.MessageDetailDomain;
import com.brucekong.slm.model.message.MessageDomain;
import com.brucekong.slm.service.forum.ForumService;
import com.brucekong.slm.service.message.MessageService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息控制类
 */
@RestController
@RequestMapping("/message")
@Slf4j
@Api(value = "消息模块", tags = "消息模块")
public class MessageController {

    // 不戴分页信息的
    private Result result = new Result();

    private PageResult pageResult = new PageResult();

    @Autowired
    private MessageService messageService;

    /**
     * 帖子列表
     *
     * @return pageResult 获取帖子列表
     */
    @GetMapping("/all")
    @SuppressWarnings("unchecked")
    @ApiOperation(value = "所有消息列表", notes = "获取所有消息列表", code = 200, produces = "application/json", responseContainer = "List", response = PageResult.class)
    public PageResult getAllMessageList(@RequestParam(name = "page", required = false, defaultValue = "1") int page,
                                   @RequestParam(name = "limit", required = false, defaultValue = "10") int limit) {
        log.info("/message/all");

        PageInfo<MessageDomain> messageServiceAllMessageList = messageService.getAllMessageList(page, limit);

        pageResult.setCode(0);
        pageResult.setMsg(null);
        pageResult.setSuccess(true);
        pageResult.setCount(messageServiceAllMessageList.getTotal());
        pageResult.setData(messageServiceAllMessageList.getList());
        return pageResult;
    }

    @GetMapping("/detail")
    @SuppressWarnings("unchecked")
    @ApiOperation(value = "获取消息详细信息", notes = "获取消息详细信息", code = 200, produces = "application/json", responseContainer = "Map", response = Result.class)
    @ApiImplicitParam(value = "消息Id", name = "id", required = true, dataType = "string", paramType = "query")
    public Result getDetailById(@ApiParam(name = "id", value = "消息Id", required = true) String id) {
        log.info("/message/detail");

        MessageDetailDomain messageDetailDomainPageInfo = messageService.getDetailById(id);

        result.setCode(0);
        result.setMsg(null);
        result.setSuccess(true);
        result.setData(messageDetailDomainPageInfo);
        return result;
    }


}